home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / awe2-0_1.lha / awe2-0.1 / Src / RCS / HardwareCpu.h,v < prev    next >
Text File  |  1988-09-28  |  4KB  |  255 lines

  1. head     1.3;
  2. access   ;
  3. symbols  ;
  4. locks    ; strict;
  5. comment  @ * @;
  6.  
  7.  
  8. 1.3
  9. date     88.09.28.22.13.50;  author grunwald;  state Exp;
  10. branches ;
  11. next     1.2;
  12.  
  13. 1.2
  14. date     88.09.21.20.51.48;  author grunwald;  state Exp;
  15. branches ;
  16. next     1.1;
  17.  
  18. 1.1
  19. date     88.09.18.16.42.08;  author grunwald;  state Exp;
  20. branches ;
  21. next     ;
  22.  
  23.  
  24. desc
  25. @@
  26.  
  27.  
  28. 1.3
  29. log
  30. @*** empty log message ***
  31. @
  32. text
  33. @#ifndef HardwareCpu_h
  34. #define HardwareCpu_h
  35.  
  36. #include "HardwareContext.h"
  37.  
  38. //
  39. //    Define the abstractions for per UNIX process resources.
  40. //
  41.  
  42. //
  43. //    Maximum number of UNIX processes that can be requested. This is
  44. //    used to size internal data structures.
  45. //
  46.  
  47. class Thread;
  48. class ReserveByException;
  49. class AwesimeHeap;
  50. class ThreadContainer;
  51. class HardSpinLock;
  52. class HardwareCpu;
  53.  
  54. typedef enum
  55. {
  56.     ExceptionNull,
  57.     ExceptionReserve,
  58.     ExceptionTerminateThread,
  59.     ExceptionDelay,
  60.     ExceptionSwitch
  61. } ExceptionCatagories;
  62.  
  63. //
  64. //    Filled in by the single original UNIX process. This value may
  65. //    change during execution
  66. //
  67. extern int HardwareCpus;
  68. extern HardwareCpu *ThisCpu;
  69.  
  70. //
  71. //    Like it says.
  72. //
  73. extern double CurrentSimulatedTime;
  74. extern const double NullTime;
  75.  
  76. class HardwareCpu {
  77. private:
  78.     Thread *currentThread;
  79.     HardwareContext systemContext;
  80.  
  81.     ThreadContainer *myCurrentEvents;
  82.     HardSpinLock *myCurrentEventsLock;
  83.     AwesimeHeap *myPendingEvents;
  84.     HardSpinLock *myPendingEventsLock;
  85.  
  86.     int iYam;    // I yam what I yam
  87.     int pid;    // ...except to UNIX
  88.  
  89.     char nameSpace[128];
  90.     char *name;
  91.  
  92.     Thread *remove();
  93.     void rendezvous();
  94.     void advanceTime();
  95.     void allocateEventStructures(int);
  96.     void deallocateEventStructures();
  97.  
  98. private:
  99.     //
  100.     //    Exception handlers.
  101.     //
  102.  
  103.     ExceptionCatagories raisedBy;
  104.  
  105.     ReserveByException *reserveToBlockOn;
  106.     Thread *threadToTerminate;
  107.     double timeToDelay;
  108.  
  109.     void raise();
  110.  
  111. //
  112. //    Public interfaces for exceptions
  113. //
  114. public:
  115.  
  116.     void reserveByException( ReserveByException * );
  117.     void threadTerminateException( Thread * );
  118.     void delayException( double time );
  119.  
  120. public:
  121.     HardwareCpu(int debug = 0);
  122.     ~HardwareCpu();
  123.  
  124.     void fireItUp(int Cpus = 1, unsigned shared = (4196 * 500));
  125.     void stirItAround();
  126.     void coolItDown();
  127.  
  128.     void terminateSimulation();
  129.  
  130.     void add(Thread *, double when);
  131.     Thread * CurrentThread();
  132.  
  133.     void debug(int newdebug);
  134.     int debug();
  135.  
  136.     int cpuId();
  137. };
  138.  
  139. inline Thread *
  140. HardwareCpu::CurrentThread()
  141. {
  142.     return( currentThread );
  143. }
  144.  
  145.  
  146. inline int HardwareCpu::cpuId()
  147. {
  148.     return( iYam );
  149. }
  150.  
  151.  
  152. inline void
  153. HardwareCpu::reserveByException( ReserveByException *sem )
  154. {
  155.     raisedBy = ExceptionReserve;
  156.     reserveToBlockOn = sem;
  157.     raise();
  158. }
  159.  
  160. inline void
  161. HardwareCpu::threadTerminateException( Thread *killMe )
  162. {
  163.     raisedBy = ExceptionTerminateThread;
  164.     threadToTerminate = killMe;
  165.     raise();
  166. }
  167.  
  168. inline double simulatedClock() {
  169.     return( CurrentSimulatedTime );
  170. }
  171.  
  172.  
  173. inline Thread *
  174. CurrentThread()
  175. {
  176.     return( ThisCpu -> CurrentThread() );
  177. }
  178.  
  179. inline void hold(double holdFor)
  180. {
  181.     ThisCpu -> delayException(holdFor);
  182. }
  183.  
  184. //
  185. //    These are things the user needs to define
  186. //
  187.  
  188. extern ThreadContainer *AllocateHardwareCurrentEventsStructure();
  189.  
  190. #endif /* HardwareCpu_h */
  191. @
  192.  
  193.  
  194. 1.2
  195. log
  196. @*** empty log message ***
  197. @
  198. text
  199. @a13 1
  200. static const int HardwareCpusMax = 16;
  201. d136 1
  202. a136 1
  203. inline double clock() {
  204. @
  205.  
  206.  
  207. 1.1
  208. log
  209. @Initial revision
  210. @
  211. text
  212. @d10 6
  213. d18 4
  214. d23 8
  215. a30 4
  216. typedef enum {ExceptionNull,
  217.           ExceptionReserve,
  218.           ExceptionTerminateThread,
  219.           ExceptionDelay } ExceptionCatagories;
  220. d32 13
  221. a45 1
  222.  
  223. d50 5
  224. d62 1
  225. d64 2
  226. a92 2
  227.     void rendezvous();
  228.  
  229. d104 2
  230. a113 4
  231. //
  232. //    Filled in by the single original UNIX process.
  233. extern int HardwareCpus;
  234. extern HardwareCpu *ThisCpu;
  235. d115 1
  236. a115 2
  237. inline Thread *
  238. CurrentThread()
  239. d117 1
  240. a117 1
  241.     return( ThisCpu -> CurrentThread() );
  242. d121 7
  243. a127 5
  244. //
  245. //    Like it says.
  246. //
  247. extern double CurrentSimulatedTime;
  248. extern const double NullTime;
  249. d129 7
  250. d141 7
  251. d153 5
  252. a157 1
  253. extern double cputime();
  254. @
  255.